package www.openteam.com.model;

import java.net.InterfaceAddress;

import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;
import www.openteam.com.base.BaseModel;
import www.openteam.com.bean.ExchangeRate;
import www.openteam.com.bean.PaperDGsm;
import www.openteam.com.bean.PaperTypeName;
import www.openteam.com.bean.PrintMesg;
import www.openteam.com.bean.ProcessDonePduReust;
import www.openteam.com.bean.ProcessDoneType;

/**
 * Created by Administrator on 2019-02-13.
 */

public class PrintModel extends BaseModel {

    public void getMesg(final MesgListener mesgListener) {
        httpApiService.findPrintMesg().subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<PrintMesg>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        mesgListener.failInfo(e.getMessage());
                    }

                    @Override
                    public void onNext(PrintMesg printMesg) {
                        mesgListener.successInfo(printMesg);
                    }
                });
    }

    public void getPaperTypeName(final PaperTypeNameListener paperTypeNameListener) {
        httpApiService.findPaperTypeName().subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<PaperTypeName>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        paperTypeNameListener.failInfo(e.getMessage());
                    }

                    @Override
                    public void onNext(PaperTypeName paperTypeName) {
                        paperTypeNameListener.successInfo(paperTypeName);
                    }
                });
    }

    public void getProcessDonePduRest(final ProcessDonePduRestListener processDonePduRestListener){
        httpApiService.findprceDonePduRequest().subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<ProcessDonePduReust>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        processDonePduRestListener.failInfo(e.getMessage());
                    }

                    @Override
                    public void onNext(ProcessDonePduReust processDonePduReust) {
                        processDonePduRestListener.successInfo(processDonePduReust);
                    }
                });
    }

    public void getProcessDoneType(final ProcessDoneTypeListener processDoneTypeListener){
        httpApiService.findprceDoneType().subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<ProcessDoneType>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        processDoneTypeListener.failInfo(e.getMessage());
                    }

                    @Override
                    public void onNext(ProcessDoneType processDoneType) {
                        processDoneTypeListener.successInfo(processDoneType);
                    }
                });

    }

    public void getExchangeRatye(final ExchangeListener exchangeListener){
        httpApiService.findExchangeRate().subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<ExchangeRate>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        exchangeListener.failInfo(e.getMessage());
                    }

                    @Override
                    public void onNext(ExchangeRate exchangeRate) {
                        exchangeListener.successInfo(exchangeRate);
                    }
                });

    }

    public void getDgsm(String typename,String papertype,String gsm,String moneyType,final DgsmListener dgsmListener){
        httpApiService.findDGsm(typename,papertype,gsm,moneyType ).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<PaperDGsm>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        dgsmListener.failInfo(e.getMessage());
                    }

                    @Override
                    public void onNext(PaperDGsm paperDGsm) {
                        dgsmListener.successInfo(paperDGsm);
                    }
                });
    }

    public interface DgsmListener{
        void successInfo(PaperDGsm paperDGsm);

        void failInfo(String str);
    }

    public interface ExchangeListener {
        void successInfo(ExchangeRate exchangeRate);

        void failInfo(String str);
    }

    public interface MesgListener {
        void successInfo(PrintMesg printMesg);

        void failInfo(String str);
    }

    public interface PaperTypeNameListener {
        void successInfo(PaperTypeName printMesg);

        void failInfo(String str);
    }

    public interface ProcessDonePduRestListener {
        void successInfo(ProcessDonePduReust processDonePduReust);

        void failInfo(String str);
    }

    public interface ProcessDoneTypeListener {
        void successInfo(ProcessDoneType processDoneType);

        void failInfo(String str);
    }
}
